﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RentAWorker.DataAccess.Interfaces;
using RentAWorker.DataAccess.Entities;
using System.Data.Objects;

namespace RentAWorker.DataAccess
{
    public class LocationDataAccess : ILocationAccess
    {
        public IEnumerable<Location> GetLocations(string searchName)
        {
            List<Location> Response = new List<Location>();
            using (BigDays2009Entities db = new BigDays2009Entities())
            {
                db.Location.MergeOption = MergeOption.NoTracking;

                IEnumerable<Location> FilteredLocations = null;
                 
                FilteredLocations = from l in db.Location
                                        where (String.IsNullOrEmpty(searchName)
                                            || l.LocationName.StartsWith(searchName))
                                    select l;

                return FilteredLocations.ToList();
            }
        }
    }
}
